package com.masterlu.leetcode.everyday.bits.simple;

/**
 * 反转二进制位
 * https://leetcode-cn.com/problems/reverse-bits/
 *
 * @Author：masterlu
 * @Date：2021/3/29 11:10 上午
 */
public class S190ReverseBits {

    public static void main(String[] args) {
        reverseBits(3);
    }

    private static int reverseBits(int n) {
        int rev = 0;
        for (int i = 0; i < 32 && n != 0; i++) {
            rev |= (n & 1) << (31 - i);
            n >>>= 1;
        }
        return rev;
    }
}
